<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>qLibc: utilities/qhash.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">qLibc
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('qhash_8c.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">qhash.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Hash APIs.  
<a href="#details">More...</a></p>

<p><a href="qhash_8c_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a3ed9a8cb5f08fa3e3c58776a62f3f54f"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qhash_8c.html#a3ed9a8cb5f08fa3e3c58776a62f3f54f">qhashmd5</a> (const void *data, size_t nbytes, void *retbuf)</td></tr>
<tr class="memdesc:a3ed9a8cb5f08fa3e3c58776a62f3f54f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculate 128-bit(16-bytes) MD5 hash.  <a href="#a3ed9a8cb5f08fa3e3c58776a62f3f54f">More...</a><br/></td></tr>
<tr class="separator:a3ed9a8cb5f08fa3e3c58776a62f3f54f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af14399e691041012350c3a82f337970e"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qhash_8c.html#af14399e691041012350c3a82f337970e">qhashmd5_file</a> (const char *filepath, off_t offset, ssize_t nbytes, void *retbuf)</td></tr>
<tr class="memdesc:af14399e691041012350c3a82f337970e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get 128-bit MD5 hash of a file contents.  <a href="#af14399e691041012350c3a82f337970e">More...</a><br/></td></tr>
<tr class="separator:af14399e691041012350c3a82f337970e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aef9d067568c8c774a1d455259612a304"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qhash_8c.html#aef9d067568c8c774a1d455259612a304">qhashfnv1_32</a> (const void *data, size_t nbytes)</td></tr>
<tr class="memdesc:aef9d067568c8c774a1d455259612a304"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get 32-bit FNV1 hash.  <a href="#aef9d067568c8c774a1d455259612a304">More...</a><br/></td></tr>
<tr class="separator:aef9d067568c8c774a1d455259612a304"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4e5daad0624e2ce2bf8c77da01228e0a"><td class="memItemLeft" align="right" valign="top">uint64_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qhash_8c.html#a4e5daad0624e2ce2bf8c77da01228e0a">qhashfnv1_64</a> (const void *data, size_t nbytes)</td></tr>
<tr class="memdesc:a4e5daad0624e2ce2bf8c77da01228e0a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get 64-bit FNV1 hash integer.  <a href="#a4e5daad0624e2ce2bf8c77da01228e0a">More...</a><br/></td></tr>
<tr class="separator:a4e5daad0624e2ce2bf8c77da01228e0a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a433dc88e449b346a863f957421c4d2ba"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qhash_8c.html#a433dc88e449b346a863f957421c4d2ba">qhashmurmur3_32</a> (const void *data, size_t nbytes)</td></tr>
<tr class="memdesc:a433dc88e449b346a863f957421c4d2ba"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get 32-bit Murmur3 hash.  <a href="#a433dc88e449b346a863f957421c4d2ba">More...</a><br/></td></tr>
<tr class="separator:a433dc88e449b346a863f957421c4d2ba"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac130b57203ec6f04fd0faa097bf14b6b"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qhash_8c.html#ac130b57203ec6f04fd0faa097bf14b6b">qhashmurmur3_128</a> (const void *data, size_t nbytes, void *retbuf)</td></tr>
<tr class="memdesc:ac130b57203ec6f04fd0faa097bf14b6b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get 128-bit Murmur3 hash.  <a href="#ac130b57203ec6f04fd0faa097bf14b6b">More...</a><br/></td></tr>
<tr class="separator:ac130b57203ec6f04fd0faa097bf14b6b"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Hash APIs. </p>

<p>Definition in file <a class="el" href="qhash_8c_source.html">qhash.c</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="a3ed9a8cb5f08fa3e3c58776a62f3f54f"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qhashmd5 </td>
          <td>(</td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>nbytes</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>retbuf</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculate 128-bit(16-bytes) MD5 hash. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>source object </td></tr>
    <tr><td class="paramname">nbytes</td><td>size of data </td></tr>
    <tr><td class="paramname">retbuf</td><td>user buffer. It must be at leat 16-bytes long.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise false.</dd></dl>
<div class="fragment"><div class="line"><span class="comment">// get MD5</span></div>
<div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> md5hash[16];</div>
<div class="line"><a class="code" href="qhash_8c.html#a3ed9a8cb5f08fa3e3c58776a62f3f54f">qhashmd5</a>((<span class="keywordtype">void</span>*)<span class="stringliteral">&quot;hello&quot;</span>, 5, md5hash);</div>
<div class="line"></div>
<div class="line"><span class="comment">// hex encode</span></div>
<div class="line"><span class="keywordtype">char</span> *md5ascii = <a class="code" href="qencode_8c.html#acf074770f495d087f9bbb268a52debb9">qhex_encode</a>(md5hash, 16);</div>
<div class="line">printf(<span class="stringliteral">&quot;Hex encoded MD5: %s\n&quot;</span>, md5ascii);</div>
<div class="line">free(md5ascii);</div>
</div><!-- fragment --> 
<p>Definition at line <a class="el" href="qhash_8c_source.html#l00067">67</a> of file <a class="el" href="qhash_8c_source.html">qhash.c</a>.</p>

</div>
</div>
<a class="anchor" id="af14399e691041012350c3a82f337970e"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qhashmd5_file </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>filepath</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">off_t&#160;</td>
          <td class="paramname"><em>offset</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">ssize_t&#160;</td>
          <td class="paramname"><em>nbytes</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>retbuf</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get 128-bit MD5 hash of a file contents. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filepath</td><td>file path </td></tr>
    <tr><td class="paramname">offset</td><td>start offset. Set to 0 to digest from beginning of file. </td></tr>
    <tr><td class="paramname">nbytes</td><td>number of bytes to digest. Set to 0 to digest until end of file. </td></tr>
    <tr><td class="paramname">retbuf</td><td>user buffer. It must be at leat 16-bytes long.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise false.</dd></dl>
<div class="fragment"><div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> md5hash[16];</div>
<div class="line"><a class="code" href="qhash_8c.html#af14399e691041012350c3a82f337970e">qhashmd5_file</a>(<span class="stringliteral">&quot;/tmp/test.dat&quot;</span>, 0, 0, md5hash);</div>
</div><!-- fragment --> 
<p>Definition at line <a class="el" href="qhash_8c_source.html#l00097">97</a> of file <a class="el" href="qhash_8c_source.html">qhash.c</a>.</p>

</div>
</div>
<a class="anchor" id="aef9d067568c8c774a1d455259612a304"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t qhashfnv1_32 </td>
          <td>(</td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>nbytes</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get 32-bit FNV1 hash. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>source data </td></tr>
    <tr><td class="paramname">nbytes</td><td>size of data</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>32-bit unsigned hash value.</dd></dl>
<div class="fragment"><div class="line">uint32_t hashval = <a class="code" href="qhash_8c.html#aef9d067568c8c774a1d455259612a304">qhashfnv1_32</a>((<span class="keywordtype">void</span>*)<span class="stringliteral">&quot;hello&quot;</span>, 5);</div>
</div><!-- fragment --><div class="fragment"><div class="line">Fowler/Noll/Vo hash</div>
<div class="line"></div>
<div class="line">The basis of <span class="keyword">this</span> hash algorithm was taken from an idea sent as reviewer</div>
<div class="line">comments to the IEEE POSIX P1003.2 committee by:</div>
<div class="line"></div>
<div class="line">    Phong Vo (http:<span class="comment">//www.research.att.com/info/kpv/)</span></div>
<div class="line">    Glenn Fowler (http:<span class="comment">//www.research.att.com/~gsf/)</span></div>
<div class="line"></div>
<div class="line">In a subsequent ballot round:</div>
<div class="line"></div>
<div class="line">    Landon Curt Noll (http:<span class="comment">//www.isthe.com/chongo/)</span></div>
<div class="line"></div>
<div class="line">improved on their algorithm.  Some people tried <span class="keyword">this</span> hash and found that</div>
<div class="line">it worked rather well. In an EMail message to Landon, they named it the</div>
<div class="line">``Fowler/Noll/Vo<span class="stringliteral">&#39;&#39;</span> or FNV hash.</div>
<div class="line"></div>
<div class="line">FNV hashes are designed to be fast <span class="keywordflow">while</span> maintaining a low collision rate.</div>
<div class="line">The FNV speed allows one to quickly hash lots of data <span class="keywordflow">while</span> maintaining</div>
<div class="line">a reasonable collision rate.  See:</div>
<div class="line"></div>
<div class="line">    http:<span class="comment">//www.isthe.com/chongo/tech/comp/fnv/index.html</span></div>
<div class="line"></div>
<div class="line"><span class="keywordflow">for</span> more details as well as other forms of the FNV hash.</div>
</div><!-- fragment --> 
<p>Definition at line <a class="el" href="qhash_8c_source.html#l00187">187</a> of file <a class="el" href="qhash_8c_source.html">qhash.c</a>.</p>

</div>
</div>
<a class="anchor" id="a4e5daad0624e2ce2bf8c77da01228e0a"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint64_t qhashfnv1_64 </td>
          <td>(</td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>nbytes</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get 64-bit FNV1 hash integer. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>source data </td></tr>
    <tr><td class="paramname">nbytes</td><td>size of data</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>64-bit unsigned hash value.</dd></dl>
<div class="fragment"><div class="line">uint64_t fnv64 = <a class="code" href="qhash_8c.html#a4e5daad0624e2ce2bf8c77da01228e0a">qhashfnv1_64</a>((<span class="keywordtype">void</span>*)<span class="stringliteral">&quot;hello&quot;</span>, 5);</div>
</div><!-- fragment --> 
<p>Definition at line <a class="el" href="qhash_8c_source.html#l00218">218</a> of file <a class="el" href="qhash_8c_source.html">qhash.c</a>.</p>

</div>
</div>
<a class="anchor" id="a433dc88e449b346a863f957421c4d2ba"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t qhashmurmur3_32 </td>
          <td>(</td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>nbytes</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get 32-bit Murmur3 hash. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>source data </td></tr>
    <tr><td class="paramname">nbytes</td><td>size of data</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>32-bit unsigned hash value.</dd></dl>
<div class="fragment"><div class="line">uint32_t hashval = <a class="code" href="qhash_8c.html#a433dc88e449b346a863f957421c4d2ba">qhashmurmur3_32</a>((<span class="keywordtype">void</span>*)<span class="stringliteral">&quot;hello&quot;</span>, 5);</div>
</div><!-- fragment --><div class="fragment"><div class="line">MurmurHash3 was created by Austin Appleby  in 2008. The initial</div>
<div class="line">implementation was published in C++ and placed in the <span class="keyword">public</span>.</div>
<div class="line">  https:<span class="comment">//sites.google.com/site/murmurhash/</span></div>
<div class="line">Seungyoung Kim has ported its implementation into C language</div>
<div class="line">in 2012 and published it as a part of qLibc component.</div>
</div><!-- fragment --> 
<p>Definition at line <a class="el" href="qhash_8c_source.html#l00258">258</a> of file <a class="el" href="qhash_8c_source.html">qhash.c</a>.</p>

</div>
</div>
<a class="anchor" id="ac130b57203ec6f04fd0faa097bf14b6b"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qhashmurmur3_128 </td>
          <td>(</td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>nbytes</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>retbuf</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get 128-bit Murmur3 hash. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>source data </td></tr>
    <tr><td class="paramname">nbytes</td><td>size of data </td></tr>
    <tr><td class="paramname">retbuf</td><td>user buffer. It must be at leat 16-bytes long.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise false.</dd></dl>
<div class="fragment"><div class="line"><span class="comment">// get 128-bit Murmur3 hash.</span></div>
<div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> hash[16];</div>
<div class="line"><a class="code" href="qhash_8c.html#ac130b57203ec6f04fd0faa097bf14b6b">qhashmurmur3_128</a>((<span class="keywordtype">void</span>*)<span class="stringliteral">&quot;hello&quot;</span>, 5, hash);</div>
<div class="line"></div>
<div class="line"><span class="comment">// hex encode</span></div>
<div class="line"><span class="keywordtype">char</span> *ascii = <a class="code" href="qencode_8c.html#acf074770f495d087f9bbb268a52debb9">qhex_encode</a>(hash, 16);</div>
<div class="line">printf(<span class="stringliteral">&quot;Hex encoded Murmur3: %s\n&quot;</span>, ascii);</div>
<div class="line">free(ascii);</div>
</div><!-- fragment --> 
<p>Definition at line <a class="el" href="qhash_8c_source.html#l00330">330</a> of file <a class="el" href="qhash_8c_source.html">qhash.c</a>.</p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_7b5d38f1875f1b693f62ca6a108a1129.html">utilities</a></li><li class="navelem"><a class="el" href="qhash_8c.html">qhash.c</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 </li>
  </ul>
</div>
</body>
</html>
